package cn.pugle.mianshi.elevator.v1;

/**
 * 电梯系统的中心管理.
 * <p> Created by tzp on 2017/9/13.
 */
public class ElevatorManager implements Runnable {
    private int elevatorNum;
    private Elevator[] elevators;

    public ElevatorManager(int elevatorNum) {
        if (elevatorNum < 1) {
            throw new RuntimeException("elevatorNum cant be less than 1");
        }
        this.elevatorNum = elevatorNum;
        elevators = new Elevator[elevatorNum];
    }

    public static void main(String[] args) {
        Thread thread = new Thread(new ElevatorManager(1));
        thread.start();
    }

    @Override
    public void run() {
        System.out.println("ElevatorManager Start");
        for (int i = 0; i < elevatorNum; i++) {//启动所有elevator
            Elevator elevator = new Elevator("elevator-" + i);
            elevators[i] = elevator;
            Thread thread = new Thread(elevator);
            thread.start();
        }


    }
}
